<?xml version="1.0" encoding="UTF-8"?>
<!--=======================================================================
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington
	Started:	2008-06-14
	Status:		release	
	Version:	2.0.0
	Build:		20080614
	License:	GNU General Public License
	======================================================================= -->

<!--=======================================================================
	Development Notes:
	==================
	20080614:	Initial release.
	=======================================================================	-->

<!--=======================================================================
	Stylesheet: sitemapX.xsl
	- Base template to renders a google sitemap
	- Is typically included by the sitemapX.xsl in the space sub-dir
	- See Notes at the end of this template...
	=======================================================================	-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<!-- Parameters defined in displayX class -->
	<xsl:param name="site"/>
	<xsl:param name="name"/>
	<xsl:param name="spaces"/>
	<xsl:param name="topic"/>
	<xsl:param name="topics"/>
	<xsl:param name="blogs"/>
	<xsl:param name="broker"/>
	<xsl:param name="link"/>
	<xsl:param name="device"/>
	
	<!-- url variables -->
	<xsl:variable name="BaseUrl_Link">http://websitex.umlungu.com/default.aspx?link=</xsl:variable>
	
<!--=======================
	Match templates section
	======================= -->
	
	<xsl:template match="/">
		<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
			<xsl:choose>
				<xsl:when test="$blogs='all'">
					<xsl:apply-templates select="//menu[not(@display='no')]/menuitem"/>
					<xsl:apply-templates select="//menu[not(@display='no')]/menuitem/menuitem"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates select="//menu[not(@display='no')]/menuitem/menuitem"/>
				</xsl:otherwise>
			</xsl:choose>
		</urlset>
	</xsl:template>	
	
	<xsl:template match="menuitem">
		<xsl:variable name="linkname"><xsl:value-of select="@link"/></xsl:variable>
		<xsl:variable name="thislink" select="//link[@name=$linkname]"/>
		<xsl:variable name="thisspace">
			<xsl:choose>
				<xsl:when test="$thislink/blog/@spaces"><xsl:value-of select="$thislink/blog/@spaces"/></xsl:when>
				<xsl:otherwise><xsl:value-of select="$thislink/parent::*/blog/@spaces"/></xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="thistopic">
			<xsl:choose>
				<xsl:when test="$thislink/blog/@topic"><xsl:value-of select="$thislink/blog/@topic"/></xsl:when>
				<xsl:otherwise><xsl:value-of select="$thislink/parent::*/blog/@topic"/></xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="thisblog">
			<xsl:choose>
				<xsl:when test="$thislink/blog/@blogs"><xsl:value-of select="$thislink/blog/@blogs"/></xsl:when>
				<xsl:otherwise><xsl:value-of select="$thislink/parent::*/blog/@blogs"/></xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:if test="$topics='all' or $thistopic=$topics">
			<xsl:if test="$thisspace=$spaces and not($thislink/@broker='sitemap')">
				<xsl:call-template name="SiteUrl">
					<xsl:with-param name="blg" select="$thisblog"/>
					<xsl:with-param name="tpc" select="$thistopic"/>
					<xsl:with-param name="lnk" select="@link"/>
				</xsl:call-template>
			</xsl:if>
		</xsl:if>
	</xsl:template>

<!--=======================
	Named templates section
	======================= -->
	
	<xsl:template name="SiteUrl">
		<xsl:param name="blg"/>
		<xsl:param name="tpc"/>
		<xsl:param name="lnk"/>
		<xsl:choose>
			<xsl:when test="$blg!='querystring'">
				<url xmlns="http://www.google.com/schemas/sitemap/0.84">
					<topic><xsl:value-of select="$tpc"/></topic>
					<blogs><xsl:value-of select="$blg"/></blogs>
					<loc>
						<xsl:value-of select="$BaseUrl_Link"/><xsl:value-of select="$lnk"/>
					</loc>
					<lastmod>
						<xsl:choose>
							<xsl:when test="$blg='all' and $topic='all'"><xsl:value-of select="//recent/blog[1]/@date"/><xsl:text>+02:00</xsl:text></xsl:when>
							<xsl:when test="$blg='all'"><xsl:value-of select="//recent/blog[@topic=$tpc][1]/@date"/><xsl:text>+02:00</xsl:text></xsl:when>
							<xsl:otherwise><xsl:value-of select="//blogs[@topic=$tpc]/blog[@id=$blg]/@date"/><xsl:text>+02:00</xsl:text></xsl:otherwise>
						</xsl:choose>
					</lastmod>
					<changefreq>weekly</changefreq>
					<priority>0.8</priority>
				</url>
			</xsl:when>
			<xsl:otherwise>
				<xsl:for-each select="//blogs[@topic=$tpc]/blog">
					<url xmlns="http://www.google.com/schemas/sitemap/0.84">
						<topic><xsl:value-of select="$tpc"/></topic>
						<blogs><xsl:value-of select="@id"/></blogs>
						<loc>
							<xsl:value-of select="$BaseUrl_Link"/><xsl:value-of select="$lnk"/>
							<xsl:text>&amp;blogs=</xsl:text><xsl:value-of select="@id"/>
						</loc>
						<lastmod><xsl:value-of select="@date"/><xsl:text>+02:00</xsl:text></lastmod>
						<changefreq>weekly</changefreq>
						<priority>0.8</priority>
					</url>
				</xsl:for-each>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	
<!--=========================
	Utility templates section
	========================= -->
	
<!--======
	Notes:
	======
	Google SiteMaps Date format:
	
	Dates must use W3C Datetime encoding, although you can omit the time portion. For instance, the following are both valid: 
	
	2005-02-21 
	2005-02-21T18:00:15+00:00 
	Dates that are in the correct format may be invalid if they specify a time but no timezone. Dates that specify no time are valid (the time defaults to 00:00:00Z).
	
	The following is an excerpt W3C
	
	(see http://www.w3.org/TR/NOTE-datetime)
	Formats
	Different standards may need different levels of granularity in the date and time, so this profile defines six levels. Standards that reference this profile should specify one or more of these granularities. If a given standard allows more than one granularity, it should specify the meaning of the dates and times with reduced precision, for example, the result of comparing two dates with different precisions.
	
	The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note that the "T" appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601. 
	
	   Year:
	      YYYY (eg 1997)
	   Year and month:
	      YYYY-MM (eg 1997-07)
	   Complete date:
	      YYYY-MM-DD (eg 1997-07-16)
	   Complete date plus hours and minutes:
	      YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
	   Complete date plus hours, minutes and seconds:
	      YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
	   Complete date plus hours, minutes, seconds and a decimal fraction of a
	second
	      YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
	where:
	
	     YYYY = four-digit year
	     MM   = two-digit month (01=January, etc.)
	     DD   = two-digit day of month (01 through 31)
	     hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
	     mm   = two digits of minute (00 through 59)
	     ss   = two digits of second (00 through 59)
	     s    = one or more digits representing a decimal fraction of a second
	     TZD  = time zone designator (Z or +hh:mm or -hh:mm)
	This profile does not specify how many digits may be used to represent the decimal fraction of a second. An adopting standard that permits fractions of a second must specify both the minimum number of digits (a number greater than or equal to one) and the maximum number of digits (the maximum may be stated to be "unlimited").
	
	This profile defines two ways of handling time zone offsets:
	
	Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ("Z"). 
	Times are expressed in local time, together with a time zone offset in hours and minutes. A time zone offset of "+hh:mm" indicates that the date/time uses a local time zone which is "hh" hours and "mm" minutes ahead of UTC. A time zone offset of "-hh:mm" indicates that the date/time uses a local time zone which is "hh" hours and "mm" minutes behind UTC. 
	A standard referencing this profile should permit one or both of these ways of handling time zone offsets.
	
	
	Examples
	1994-11-05T08:15:30-05:00 corresponds to November 5, 1994, 8:15:30 am, US Eastern Standard Time.
	1994-11-05T13:15:30Z corresponds to the same instant.
	
-->

</xsl:stylesheet>